package cn.gs.serializable.serialize;

// @author gs
import cn.gs.serializable.entity.IEntity;
import cn.gs.serializable.entity.OneEntity;

public class BooleanSerialize implements ISerialize {

    @Override
    public <T> T toObj(cn.gs.serializable.serialize.ISerialize ctrl, IEntity from, Class<T> clazz) {
        if (from != null && from instanceof OneEntity) {
            String t = ((OneEntity) from).getValue();
            if (t != null) {
                return (T) (t.equalsIgnoreCase("true") ? Boolean.TRUE : t.equalsIgnoreCase("false") ? Boolean.FALSE : null);
            }
        }
        return null;
    }

    @Override
    public IEntity fromObj(ISerialize ctrl, Object from) {
        if (from instanceof Boolean) {
            return new OneEntity(from.toString());
        }
        return null;
    }
}
